#!/bin/sh /etc/rc.common
# Copyright (C) 2014 Emong
# http://blog.emong.me

START=99
init() {
	. /lib/functions.sh
	. /lib/functions/network.sh
	config_load emongbwctrl
}

ip_config_get() {
	config_get ip $1 ip
	config_get enable $1 enable
	config_get downbw $1 downbw
	config_get upbw $1 upbw
	[ "$enable" == "1" ] && {
		logger -t emongbwctrl list: limit $ip down:$downbw,up:$upbw
		setclientbw.sh $ip $downbw $upbw
	}
}

start() {
	init
	config_get isenable config enable
	network_get_device DEVICE lan
	[ "$isenable" == "1" ] && {
		setifbroot.sh
		/usr/sbin/redirectifb.sh $DEVICE
		config_foreach ip_config_get ip-limit
	}
}

stop() {
	init
	network_get_device DEVICE lan
	tc qdisc del dev ifb0 root
	tc qdisc del dev ifb1 root
	tc qd del dev $DEVICE root
	tc qdisc del dev $DEVICE handle ffff: ingress
	ifconfig ifb0 down
	ifconfig ifb1 down
}


